import webinfo from "./webinfo";
import { FILETYPE } from "@/utils/config";
export default {
  mixins: [webinfo],
  data() {
    return {};
  },
  computed: {
    //头像
    headImg() {
      return function(v) {
        return v.sysAttachment ? v.sysAttachment.httpUrl : this.headPic;
      };
    },
    //封面图
    coverImg() {
      return function(v) {
        if (v.fileId) {
          return v.sysAttachment.httpUrl;
        } else {
          let type = this.$store.getters.libraryType;
          return this.defaultLibraryImg(type);
        }
      };
    },
    //搜索封面图
    coverImgFile() {
      return function(v) {
        if (v.httpUrl) {
          return v.httpUrl;
        } else if (v.sysAttachment) {
          return v.sysAttachment.httpUrl;
        } else {
          return this.defaultCourseImg;
        }
      };
    },
    //团队人员
    teamInfo() {
      return function(v) {
        if (v.sysCourseTeamList.length) {
          let team = v.sysCourseTeamList.filter((v) => v.auditStatus == 2);
          return team.map((m) => m.userName).toString();
        } else {
          return "--";
        }
      };
    },
    //单位名称
    deptName() {
      return function(v) {
        return v.tbSysDept ? v.tbSysDept.name : "";
      };
    },
    //单位名称
    knowledge() {
      return function(v) {
        return v.sysIdeologicalEducation ? v.sysIdeologicalEducation.name : "";
      };
    },
  },
  methods: {
    // 知识点封面图
    knowledgeCoverImg(v) {
      if (!v) return;
      //没有设置封面图时，设置附件里面的图片作为封面图
      let fileInImg = "";
      if (v.hasOwnProperty("sysKnowledgeFilesList")) {
        let imgArr = v.sysKnowledgeFilesList.filter((v) =>
          FILETYPE.img.includes(v.type)
        );
        if (imgArr.length) {
          fileInImg = imgArr[0].sysAttachment.httpUrl;
        }
      }
      if (v.hasOwnProperty("sysAttachment")) {
        return v.sysAttachment.httpUrl;
      } else if (fileInImg) {
        return fileInImg;
      } else {
        return this.$store.getters.defaultKnowledgeImg;
      }
    },
    getNames(v) {
      let { sourceUnit, tbSysDept } = v;
      let deptNames = this.foo(tbSysDept, sourceUnit);
      return deptNames.substr(1, deptNames.length - 2);
    },
    foo(data) {
      return data.deptFullnamepath;
    },
  },
};
